import CryptoJS from 'crypto-js';
import { v4 as uuidv4 } from 'uuid';

// 固定盐
const fixedSalt = 'tn+feZJhSYi#qvCa+yao';
function generateUniqueRandomId(): string {
    // 生成基于时间的 UUID
    return uuidv4();
}

const randomId = generateUniqueRandomId();

// 创建一个带有固定盐的密码散列
export const createHashWithFixedSalt = (password:string) => {
    const hashedPassword = CryptoJS.SHA256(password + fixedSalt).toString(CryptoJS.enc.Hex);
    return {
        hashedPassword
    };
};

// 文件流加密，校验完整性
export const createHashFile = (file:any) => {
    const hashedFile = CryptoJS.SHA256(CryptoJS.lib.WordArray.create(file));
    return {
        hashedFile
    };
};

// 文件唯一标识ID
export const createHashFileId = (uid:any) => {
    const hashedFileId = CryptoJS.SHA256(uid+randomId).toString();
    return {
        hashedFileId
    };
};
